//
// Created by 卞证 on 2021/05/19.
//

#include "undirected_graph.hpp"
#include <iostream>
#include <set>
#include <vector>

using namespace std;
using namespace SpanTree;

int main(int argc, char **argv) {
    if (argc != 3) {
        std::cout << argv[0] << " knn_graph_file save_graph_file" << std::endl;
        exit(-1);
    }
    printf("knn_graph_fname %s\nsave_graph_file %s\n", argv[1], argv[2]);

    char *knn_graph_fname = argv[1];
    char *save_graph_fname = argv[2];
    vector<set<int>> knn_graph = load_efanna(knn_graph_fname);

    int n_vertex = knn_graph.size();
    bool is_connected = true;

    for (int i = 0; i < n_vertex; i++) {
        if ((int) knn_graph[i].size() == 0) {
            is_connected = false;
            break;
        }
    }
    if (!is_connected) {
        printf("origin graph not connected\n");
    } else {
        printf("origin graph connected\n");
    }
    vector<pair<int, int>> res_graph = to_undirected(knn_graph);
    printf("n_edge %d\n", (int) res_graph.size());
    if (!is_connected) {
        printf("undirected graph not connected\n");
    } else {
        printf("undirected graph connected\n");
    }
    printf("chang to undirected graph\n");

    save_edge_graph(save_graph_fname, res_graph, n_vertex);

    return 0;
}
